<?php
//此文档为算法赛报名页
require_once("./bm_header.php");
$is_admin = isset($_SESSION['administrator']) || isset($_SESSION[$BM_ADMIN]);
if (isset($_GET['cid']))
{
	$cid=intval($_GET['cid']);
	require_once("./judgecid.php");//判断查看权限、比赛id合法性等等非正常访问
	
	
	$ckind = $_GET['ckind'];
	if($ckind == 0)
	{
		if(!$is_admin && ($now < $contest_0_start || $now > $contest_0_end))
		{
		?>
				<script language='javascript'>
				alert('未在注册时间，不可删除!');
				history.go(-1);
				</script>";
				<div class="content bolr">
		        <h2 class="h2">未在注册时间，不可删除!</h2>
				<div style="height:150px;"></div>
				</div>
		<?php 	
		require_once("bm_footer.php");
		exit(0);
		}
	}
	else 
	{
		if(!$is_admin && ($now < $contest_1_start || $now > $contest_1_end))
		{
		?>
				<script language='javascript'>
				alert('未在注册时间，不可删除!');
				history.go(-1);
				</script>";
				<div class="content bolr">
		        <h2 class="h2">未在注册时间，不可删除!</h2>
				<div style="height:150px;"></div>
				</div>
		<?php 
		require_once("bm_footer.php");
		exit(0);
		}
	}
		
	$user_id = $_SESSION['user_id'];
	
	//读教练信息
	$sql="SELECT * FROM `cr_user` WHERE `user_id`='$user_id' ";
	$result=mysql_query($sql);
	$row=mysql_fetch_object($result);	
	$school = $row->user_school;
	mysql_free_result($result);
	
	$team_id = $_GET['tid'];
	$sql="SELECT * FROM `cr_team` WHERE `team_id`='$team_id' ";
	$result=mysql_query($sql);
	$rows_cnt=mysql_num_rows($result);
	if($rows_cnt == 0)
	{
		?>
				<script language='javascript'>
				alert('没有这样一支队伍!');
				history.go(-1);
				</script>";
				<div class="content bolr">
		        <h2 class="h2">没有这样一支队伍!</h2>
				<div style="height:150px;"></div>
				</div>
		<?php 
		require_once("bm_footer.php");
		exit(0);
	}
	$row=mysql_fetch_object($result);
	if($row->team_school != $school)//如果教练不是这个队伍的学校的（只有通过修改get的网址才会遇到这情况）
	{
		?>
				<script language='javascript'>
				alert('没有删除权限!');
				history.go(-1);
				</script>";
				<div class="content bolr">
		        <h2 class="h2">没有删除权限!</h2>
				<div style="height:150px;"></div>
				</div>
		<?php 
		require_once("bm_footer.php");
		exit(0);
	}
	
	$team_name = $row->team_name;
	$team_school = $row->team_school;
	
	mysql_free_result($result);
	$sql="DELETE FROM `cr_stu` WHERE `team_id`=$team_id";
	mysql_query($sql);// or die(mysql_error());
	$sql="DELETE FROM `cr_team` WHERE `team_id`=$team_id";
	mysql_query($sql);// or die(mysql_error());
}
	

require_once("bm_footer.php");
?>

<script language=javascript>
	history.go(-1);
</script>